Add VBD delete and flush commands.
Yay, xenctl-cmdline should now be the union of domctl/xenctl-web/vdmanager's functionality.
3f05631dMY7PMkwSY7zBFelGJ8goVg tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
3f05631dYDFXv6mwNFAgz3ta9kShJA tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
3f0bdfabfXM4tMbvmV06di5U-5FfqA tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java
+3f0bf89f_DkClyexDd4EDwinZJG83A tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java
+3f0bf89fvzPQqcHBq1xA0XlFiO8tLA tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java
3f0bec93F_VDIcn9oeXwJYwydX20kg tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
3f098761TRsbDk9woUM846Q6_F7EmA tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java
3f099009pmH9MFkRYwP2V1DfsqEwdg tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
3f05631eGWxq7bojQbMa-tGxsENIhw tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java
3f0bdfab88VYiD26FXCDmmAAGJ8zWA tools/control/src/org/xenoserver/control/CommandVbdCreate.java
3f0bdfabI14M5_odjCIwQbXCdauReA tools/control/src/org/xenoserver/control/CommandVbdCreatePhysical.java
+3f0bf89fcVy1cFU18hPVXkFMMLHLug tools/control/src/org/xenoserver/control/CommandVbdDelete.java
+3f0bf8a0aRDXkIGy3liS1oKXIQpeyA tools/control/src/org/xenoserver/control/CommandVbdFlush.java
3f098761c5-idlmf9vWEMOlDw0VCHg tools/control/src/org/xenoserver/control/CommandVdCreate.java
3f0990096KcyQw77qJmjTu941smS8A tools/control/src/org/xenoserver/control/CommandVdDelete.java
3f0990093VJUL7QjxGigR5GPXf_Fkw tools/control/src/org/xenoserver/control/CommandVdRefresh.java
};
private static final CommandParser vbdcommands[] =
{ new ParseVbdCreate(),
+ new ParseVbdDelete(),
+ new ParseVbdFlush(),
new ParseVbdShow()
};
private static final CommandParser commands[] =
--- /dev/null
+package org.xenoserver.cmdline;
+
+import java.util.LinkedList;
+
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandVbdDelete;
+import org.xenoserver.control.Defaults;
+
+public class ParseVbdDelete extends CommandParser {
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ int domain_id = getIntParameter(args, 'n', 0);
+ int vbd_num = getIntParameter(args, 'v', -1);
+
+ if (domain_id == 0) {
+ throw new ParseFailedException("Expected -n<domain_id>");
+ }
+ if (vbd_num == -1) {
+ throw new ParseFailedException("Expected -v<vbd_num>");
+ }
+ loadState();
+ String output = new CommandVbdDelete(domain_id, vbd_num).execute();
+ if (output != null) {
+ System.out.println(output);
+ }
+ saveState();
+ }
+
+ public String getName() {
+ return "delete";
+ }
+
+ public String getUsage() {
+ return "-n<domain> -v<vbd>";
+ }
+
+ public String getHelpText() {
+ return "Deletes the specified virtual block device from the specified domain.";
+ }
+
+}
--- /dev/null
+package org.xenoserver.cmdline;
+
+import java.util.LinkedList;
+
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandVbdFlush;
+import org.xenoserver.control.Defaults;
+
+public class ParseVbdFlush extends CommandParser {
+ public void parse(Defaults d, LinkedList args)
+ throws ParseFailedException, CommandFailedException {
+ loadState();
+ String output = new CommandVbdFlush().execute();
+ if (output != null) {
+ System.out.println(output);
+ }
+ saveState();
+ }
+
+ public String getName() {
+ return "flush";
+ }
+
+ public String getUsage() {
+ return "";
+ }
+
+ public String getHelpText() {
+ return "Delete all virtual block devices";
+ }
+}
--- /dev/null
+package org.xenoserver.control;
+
+/**
+ * Delete a virtual block device. Note that this does not update anything inside
+ * Xen, and therefore should only be done if you are certain that the domain has
+ * either not been started, or has been destroyed, or you are sure it will not
+ * try to access the VBD again. Since the mapping is not removed in Xen, any
+ * subsequent changes to the underlying virtual disk will affect the domain,
+ * probably adversely.
+ */
+public class CommandVbdDelete extends Command {
+ /** Domain id to delete from */
+ private int domain_id;
+ /** VBD number to delete */
+ private int vbd_num;
+
+ /**
+ * Constructor for CommandVbdDelete.
+ * @param domain_id Domain ID to delete from
+ * @param vbd_num VBD number to delete
+ */
+ public CommandVbdDelete(int domain_id, int vbd_num) {
+ this.domain_id = domain_id;
+ this.vbd_num = vbd_num;
+ }
+
+ /**
+ * @see org.xenoserver.control.Command#execute()
+ */
+ public String execute() throws CommandFailedException {
+ if (VirtualDiskManager
+ .IT
+ .deleteVirtualBlockDevice(domain_id, vbd_num)) {
+ return "Deleted VBD " + vbd_num + " from domain " + domain_id;
+ } else {
+ throw new CommandFailedException(
+ "No such virtual block device "
+ + vbd_num
+ + " in domain "
+ + domain_id);
+ }
+ }
+}
--- /dev/null
+package org.xenoserver.control;
+
+/**
+ * Flush (delete) all virtual block devices.
+ */
+public class CommandVbdFlush extends Command {
+ /**
+ * @see org.xenoserver.control.Command#execute()
+ */
+ public String execute() throws CommandFailedException {
+ VirtualDiskManager.IT.flushVirtualBlockDevices();
+ return "Flushed virtual block devices";
+ }
+}
* Delete a virtual block device.
* @param domain Domain owning the device.
* @param vbdNum The vbd number within the domain.
+ * @return true if the VBD was deleted, false if it does not exist.
*/
- void deleteVirtualBlockDevice(int domain, int vbdNum) {
+ boolean deleteVirtualBlockDevice(int domain, int vbdNum) {
Object hash = hashVBD(domain, vbdNum);
- virtualBlockDevices.remove(hash);
+ return virtualBlockDevices.remove(hash) != null;
}
/**